package com.test.basic;

/**
 * 反转链表
 * 循环
 *
 */
public class ReverseLinkedList {
    public static void main(String[] args) {

    }

    //定义node节点
    class ListNode{
        private int value;
        private ListNode next;

        public ListNode(int value){
            this.value = value;
            this.next = null;
        }

        public ListNode reverseList(ListNode head){
           if(head == null || head.next == null){
               return head;
           }
           ListNode first = head;
           ListNode second = null;
           ListNode result = null;
           while (first!=null){
               second = first.next;
               first.next = result;
               result = first ;
               first = second ;
           }
           return result;
        }
    }
}
